package net.huashitong.user.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.huashitong.user.databean.PostilDatabean;
import net.huashitong.user.databean.VoiceRecordDatabean;
import net.huashitong.user.entity.VoiceRecord;
import net.huashitong.user.filter.VoiceRecordFilter;
import net.huashitong.user.service.VoiceRecordService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;
import com.sirdc.modules.utils.ObjectUtils;

/**
 * 语音记录
 * @author lzr
 *
 */
@Controller
@RequestMapping("/app/voiceRecord")
public class VoiceRecordController extends JsonBaseController {

	@Autowired
	private VoiceRecordService recordService;
	@Override
	protected String getView(String arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	/**
	 * 保存语音记录
	 * @param filter
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/saveVoiceRecord")
	public Message saveVoiceRecord(@RequestBody VoiceRecordFilter filter){
		
		VoiceRecord record = new VoiceRecord();
		
		record.setUserId(filter.getUserId());
		record.setDate(filter.getDate());
		record.setVoiceDescription(filter.getVoiceDescription());
		record.setBeginTime(filter.getBeginTime());
		record.setEndTime(filter.getEndTime());
		recordService.save(record);
		return coverMessage("200", "保存成功");
	}
	/**
	 * 获取语音记录
	 * @param filter
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/queryVoiceRecord")
	public Message queryVoiceRecord(@RequestBody VoiceRecordFilter filter){
		List<VoiceRecord> records = recordService.queryByfilter(filter);
		List<VoiceRecordDatabean> databeans = new ArrayList<VoiceRecordDatabean>();
		for (VoiceRecord voiceRecord : records) {
			VoiceRecordDatabean databean = new VoiceRecordDatabean();
			databean.setVoiceDescription(voiceRecord.getVoiceDescription());
			databean.setBeginTime(voiceRecord.getBeginTime());
			databean.setEndTime(voiceRecord.getEndTime());
			databeans.add(databean);
		}
		return coverMessage("200", "数据获取成功", databeans);
	}
	/**
	 * 获取有语音日期
	 * @param filter
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/queryDate")
	public Message queryDate(@RequestBody VoiceRecordFilter filter){
		List<String> dates = recordService.queryByUserId(filter.getUserId());
		List<VoiceRecordDatabean> databeans = new ArrayList<VoiceRecordDatabean>();
		for (String date : dates) {
			VoiceRecordDatabean databean = new VoiceRecordDatabean();
			databean.setDate(date);
			databeans.add(databean);
		}
		return coverMessage("200", "数据获取成功", databeans);
	}
}
